package cn.lisens.modules.file.controller;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.ServletRequest;

import cn.lisens.common.controller.BaseController;
import cn.lisens.modules.file.model.FileUpload;
import cn.lisens.modules.file.model.FileUploadParams;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;

@Controller
@RequestMapping({ "${adminPath}/file" })
public class FileUploadController extends BaseController{
   
	@GetMapping(value = "")
	public String file( ModelMap model) {
	    return "modules/file/file-form";
	}
	
	@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
	public String submit(@RequestParam("file") MultipartFile file, ModelMap modelMap) {
	    modelMap.addAttribute("file", file);
	    return "modules/file/file-view";
	}
	
	@RequestMapping(value = "/uploadMultiFile", method = RequestMethod.POST)
	public String submit(@RequestParam("files") MultipartFile[] files, ModelMap modelMap) {
	    modelMap.addAttribute("files", files);
	    return "fileUploadView";
	}


	
	@RequestMapping("upload")
    @ResponseBody
    public Map<String, Object> upload(FileUploadParams params) {
        return null;
    }
    
    @RequestMapping("fileList")
    @ResponseBody
    public String fileList(FileUpload fileUpload, Boolean bizKeyIsLike) {
//        if (StringUtils.isNotBlank((CharSequence)fileUpload.getBizKey()) && StringUtils.isNotBlank((CharSequence)fileUpload.getBizType())) {
//            if (bizKeyIsLike != null && bizKeyIsLike) {
//                final String bizKey = null;
//                fileUpload.setBizKey_rightLike(fileUpload.getBizKey());
//                fileUpload.setBizKey(bizKey);
//            }
//            final List a;
//            if ((a = this.fileUploadService.findList(fileUpload)) != null && a.size() > 0) {
//                return JsonMapper.toJson((Object)a);
//            }
//        }
//        return this.renderResult("false", "");
        return "";
    }
    
    @RequestMapping(value = "/download/{fileUploadId}", method = RequestMethod.GET)
    public String download(@PathVariable("fileUploadId") String fileUploadId, String preview, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return "";
    }
}
